home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Pascal / Applications / NIH Image 1.60 / 1.60 Source / RealUtils.p < prev    next >
Encoding:
Text File  |  1996-03-01  |  2.4 KB  |  110 lines  |  [TEXT/MPPS]

  1. unit realUtils;
  2.  
  3. interface
  4.     uses
  5.         Types, Memory, QuickDraw, Packages, Menus, Events, Fonts, ToolUtils, globals, Utilities, Graphics;
  6.  
  7. function NewRealWindow (name: str255; width, height: LongInt): boolean;
  8. procedure DisplayRealImage(rData: rImagePtr; min, max: real; BlackIsZero: boolean);
  9. function ConvertToReal:boolean;
  10.  
  11.  
  12. implementation
  13.  
  14.  
  15. function NewRealWindow (name: str255; width, height: LongInt): boolean;
  16. var
  17.     TempH: handle;
  18. begin
  19.     tempH := GetBigHandle(width * height * SizeOf(real));
  20.     if TempH = nil then begin
  21.         PutMemoryAlert;
  22.         NewRealWindow := false;
  23.         exit(NewRealWindow);
  24.     end;
  25.     if not NewPicWindow(name, width, height) then begin
  26.         DisposeHandle(handle(TempH));
  27.         exit(NewRealWindow);
  28.     end;
  29.     info^.DataH := tempH;
  30.     UpdateTitleBar;
  31.     UpdateWindowsMenuItem;
  32.     NewRealWindow := true;
  33. end;
  34.  
  35.  
  36.     procedure DisplayRealImage(rData: rImagePtr; min, max: real; BlackIsZero: boolean);
  37.         var
  38.             row, col, i, base, width, height: LongInt;
  39.             r, scale: real;
  40.             line: lineType;
  41.     begin
  42.         with info^ do begin
  43.             width := pixelsPerLine;
  44.             height := nLines;
  45.         end;
  46.         scale := 255.0 / (max - min);
  47.         for row := 0 to height - 1 do begin
  48.                 base := row * width;
  49.                 for col := 0 to width - 1 do begin
  50.                         r := rData^[base + col];
  51.                         line[col] := round((r - min) * scale);
  52.                 end;
  53.                 PutLine(0, row, width, line);
  54.             end;
  55.         if BlackIsZero then
  56.             InvertPic;
  57.         with info^ do begin
  58.             Changes := true;
  59.             fit:=StraightLine;
  60.             nCoefficients := 2;
  61.             if BlackIsZero then begin
  62.                 coefficient[1] := max;
  63.                 coefficient[2] := -1.0/scale;
  64.             end else begin
  65.                 coefficient[1] := min;
  66.                 coefficient[2] := 1.0/scale;
  67.             end;
  68.             nKnownValues := 0;
  69.             ZeroClip := false;
  70.             UpdateTitleBar;
  71.         end;
  72.     end;
  73.     
  74.     
  75. function ConvertToReal:boolean;
  76. var
  77.     row, col, i, sum, base: LongInt;
  78.     width, height: LongInt;
  79.     line: LineType;
  80.     rData: rImagePtr;
  81.     TempH: handle;
  82. begin
  83.     with info^ do begin
  84.         width := pixelsPerLine;
  85.         height := nLines;
  86.         tempH := GetBigHandle(width * height * SizeOf(real));
  87.         if TempH = nil then begin
  88.             PutMemoryAlert;
  89.             ConvertToReal := false;
  90.             exit(ConvertToReal);
  91.         end;
  92.         dataH := tempH;
  93.         hlock(dataH);
  94.         rData := rImagePtr(dataH^);
  95.     end;
  96.     for row:= 0 to height - 1 do begin
  97.         GetLine(0, row, width, line);
  98.         base := row * width;
  99.         for col := 0 to width - 1 do
  100.             rData^[base + col] := line[col];
  101.     end;
  102.     hunlock(info^.dataH);
  103.     UpdateTitleBar;
  104.     UpdateWindowsMenuItem;
  105.     ConvertToReal := true;
  106. end;
  107.  
  108.  
  109.  
  110. end. {realUtils Unit}